com.rscja.deviceapi

## Class Printer

- java.lang.Object
- - com.rscja.deviceapi.Printer

- All Implemented Interfaces:
    IPrinter

      public class Printer
      extends java.lang.Object
      implements IPrinter

  打印机操作类
  Printer operation type
  Author:
    Administrator

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Printer.BarcodeType` 1D条码类型
    `static class` | `Printer.PrinterStatus`
    `static interface` | `Printer.PrinterStatusCallBack`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearCache()` 立即清空打印缓存,清空打印机接收缓冲区和打印缓冲区 Clear up printing cache, clear printer receive zone and buffer zone
    `boolean` | `eraseFlash()`
    `boolean` | `eraseFW(long size)`
    `boolean` | `free()` 关闭打印机模块 Switch off printer module
    `static Printer` | `getInstance()` 获取打印机模块操作实例 Acquire printer module operation Instance
    `int` | `getPrintCodePage()`
    `int` | `getPrinterType()`
    `java.lang.String` | `getVersion()`
    `boolean` | `init(int isUpgrade)` 打开打印机模块 Switch on printer module
    `boolean` | `initFW()`
    `boolean` | `initPrinterGpio(boolean isUpgrade)`
    `boolean` | `isPowerOn()`
    `boolean` | `openPrinterSerialPort(boolean isUpgrade)`
    `void` | `print(android.graphics.Bitmap bitmap)` 打印图片 print picture
    `void` | `print(android.graphics.Bitmap bitmap, int interval)` 打印图片 print picture
    `void` | `print(android.graphics.Bitmap bitmap, int mode, int interval)` 打印图片 print pciture
    `void` | `print(byte[] content)` 打印字符 print character
    `void` | `print(java.lang.String content)` 打印字符 printe character
    `void` | `print(java.lang.String barcodeData, Printer.BarcodeType barcodeType)` 打印条码 print barcode
    `void` | `print(java.lang.String content, java.lang.String charsetName)` 打印字符 print character
    `int` | `receiveData(byte[] outData)` 接收串口数据 receive serial port data
    `boolean` | `releasePrinterGpio()`
    `void` | `restoreDefault()` 参数还原默认值 parameter reset to default
    `int` | `sendAndReceiveData(byte[] sendData, byte[] outData)` 收发数据 sent/received data
    `int` | `sendData(byte[] sendData)` 发送数据到串口 send data to serial port
    `void` | `setBarcodeHeight(int height)` 设置一维条码的高度 Setup 1D barcode height
    `void` | `setBarcodeHRI(int position)` 设置一维条码可读字符（HRI）打印位置 setup 1D barcode readable character (HRI) print position
    `void` | `setBarcodeWidth(int width)` 设置一维条码的宽度 Setup 1D barcode width
    `void` | `setFeedRow(int n)` 打印并进纸 n行 print and paper infeed n
    `void` | `setPrintCharacterStyle(boolean italic, boolean frame, boolean bold, boolean doubleWidth, boolean doubleHigh, boolean white, boolean underline)` 设置字体样式 set font style
    `void` | `setPrintCodePage(int page)`
    `void` | `setPrinterStatusCallBack(Printer.PrinterStatusCallBack callBack)` 设置接收打印机状态的回调 set call back of printer received status
    `void` | `setPrinterStatusCallBackEnable(boolean b)` 设置是否接收打印机状态回调消息 Setup receive printer status return message or not
    `void` | `setPrinterType(int type)`
    `void` | `setPrintGrayLevel(int gray)` 设置打印 灰度 setup print grey level
    `void` | `setPrintLeftMargin(int margin)` 设置左边距 Setup left margin
    `void` | `setPrintRightMargin(int margin)` 设置左边距 Setup right margin
    `void` | `setPrintRowSpacing(int spacing)` 设置行间距(若设定的行间距小于一行中的最大字符高度，那么该行行间距等于最大字符高度) Setup line spacing (if the set value is less than max.charater height, then the line spacing equals to max.character height)
    `void` | `setPrintSpeed(int speed)` 设置打印速度 setup print velocity
    `boolean` | `upgradeFont(int packageCount, int index, int currSize, byte[] data)`
    `boolean` | `upgradeFW(int packageCount, int index, int currSize, byte[] data)`
    `boolean` | `verifyFW(int upgradeCRC)`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getInstance

          public static Printer getInstance()
                                     throws ConfigurationException

      获取打印机模块操作实例
      Acquire printer module operation Instance
      Returns:
        打印机模块操作实例
        printer module operation Instance
      Throws:
        `ConfigurationException`

    - #### setPrinterStatusCallBackEnable

          public void setPrinterStatusCallBackEnable(boolean b)

      设置是否接收打印机状态回调消息
      Setup receive printer status return message or not
      Specified by:
        `setPrinterStatusCallBackEnable` in interface `IPrinter`
      Parameters:
        `b` - true:表示接收打印机回调消息，false:表示不接收回调消息,默认是true
        ture: means receive return infor of printer, false: means donot receive return infor,default is ture.

    - #### receiveData

          public int receiveData(byte[] outData)

      接收串口数据
      receive serial port data
      Specified by:
        `receiveData` in interface `IPrinter`
      Parameters:
        `outData` - 接收到的数据
        outData received data
      Returns:
        返回接收数据的长度
        length of returned data

    - #### sendData

          public int sendData(byte[] sendData)

      发送数据到串口
      send data to serial port
      Specified by:
        `sendData` in interface `IPrinter`
      Parameters:
        `sendData` - 发送的数据
        send data
      Returns:
        返回发送数据的长度
        length of return sent data

    - #### sendAndReceiveData

          public int sendAndReceiveData(byte[] sendData,
                                        byte[] outData)

      收发数据
      sent/received data
      Specified by:
        `sendAndReceiveData` in interface `IPrinter`
      Parameters:
        `sendData` - 发送的数据
        sent data
        `outData` - 接收的数据
        received data
      Returns:
        返回接收的数据长度(- 1表示发送失败)
        returned data length(-1 means send failed)

    - #### setPrinterStatusCallBack

          public void setPrinterStatusCallBack(Printer.PrinterStatusCallBack callBack)

      设置接收打印机状态的回调
      set call back of printer received status
      Specified by:
        `setPrinterStatusCallBack` in interface `IPrinter`
      Parameters:
        `callBack` -

    - #### init

          public boolean init(int isUpgrade)

      打开打印机模块
      Switch on printer module
      Specified by:
        `init` in interface `IPrinter`
      Returns:
        成功true，失败false

    - #### initPrinterGpio

          public boolean initPrinterGpio(boolean isUpgrade)

      Specified by:
        `initPrinterGpio` in interface `IPrinter`

    - #### releasePrinterGpio

          public boolean releasePrinterGpio()

      Specified by:
        `releasePrinterGpio` in interface `IPrinter`

    - #### openPrinterSerialPort

          public boolean openPrinterSerialPort(boolean isUpgrade)

      Specified by:
        `openPrinterSerialPort` in interface `IPrinter`

    - #### free

          public boolean free()

      关闭打印机模块
      Switch off printer module
      Specified by:
        `free` in interface `IPrinter`
      Returns:
        成功true，失败false
        true means success, false means failed

    - #### print

          public void print(byte[] content)

      打印字符
      print character
      Specified by:
        `print` in interface `IPrinter`
      Parameters:
        `content` - 打印的内容

    - #### print

          public void print(java.lang.String content)

      打印字符
      printe character
      Specified by:
        `print` in interface `IPrinter`
      Parameters:
        `content` - 打印的内容
        print content

    - #### print

          public void print(java.lang.String content,
                            java.lang.String charsetName)

      打印字符
      print character
      Specified by:
        `print` in interface `IPrinter`
      Parameters:
        `content` - 打印的内容
        print content
        `charsetName` - 字符编码格式
        character coding format

    - #### print

          public void print(android.graphics.Bitmap bitmap,
                            int mode,
                            int interval)

      打印图片
      print pciture
      Specified by:
        `print` in interface `IPrinter`
      Parameters:
        `bitmap` - 要打印的图片
        picture for printing
        `mode(0,1,32,33)` - 点图格式:
        picture format:
        模式 水平比例 垂直比例
        format horizontal scale vertical scale
        0: 8 点单密度 ×2 ×3
        0: 8 point single density ×2 ×3
        1: 8 点双密度 ×1 ×3
        1: 8 point dual density ×1 ×3
        32:24 点单密度 ×2 ×1
        32:24 point single density ×2 ×1
        33:24 点双密度 ×1 ×1
        33:24 point dual density ×1 ×1

    - #### print

          public void print(android.graphics.Bitmap bitmap,
                            int interval)

      打印图片
      print picture
      Specified by:
        `print` in interface `IPrinter`
      Parameters:
        `bitmap` - 图片数据
        bitmap picture data
        `interval` - 发送每行数据的时间间隔
        Time interval for sending per row of data

    - #### print

          public void print(android.graphics.Bitmap bitmap)

      打印图片
      print picture
      Specified by:
        `print` in interface `IPrinter`
      Parameters:
        `bitmap` - 图片数据
        bitmap picture data

    - #### print

          public void print(java.lang.String barcodeData,
                            Printer.BarcodeType barcodeType)
                     throws PrinterBarcodeInvalidException

      打印条码
      print barcode
      Specified by:
        `print` in interface `IPrinter`
      Parameters:
        `barcodeData` - 条码数据
        barcodeData
        `barcodeType` - 条码类型
        barcodeType
      Throws:
        `PrinterBarcodeInvalidException`

    - #### setFeedRow

          public void setFeedRow(int n)

      打印并进纸 n行
      print and paper infeed n
      Specified by:
        `setFeedRow` in interface `IPrinter`
      Parameters:
        `n(0-255)` -

    - #### setPrintRowSpacing

          public void setPrintRowSpacing(int spacing)

      设置行间距(若设定的行间距小于一行中的最大字符高度，那么该行行间距等于最大字符高度)
      Setup line spacing (if the set value is less than max.charater height, then the line spacing equals to max.character height)
      Specified by:
        `setPrintRowSpacing` in interface `IPrinter`
      Parameters:
        `spacing` - (0 ≤ spacing ≤ 255), 默认值33
        spacing (0≤ spacing ≤ 255), default 33

    - #### setPrintLeftMargin

          public void setPrintLeftMargin(int margin)

      设置左边距
      Setup left margin
      Specified by:
        `setPrintLeftMargin` in interface `IPrinter`
      Parameters:
        `margin` - (0 ≤ left margin ≤ 47，且 0 ≤ （左边距 + 右边距） ≤ 47), 默认值0
        margin (0 ≤ left margin ≤ 47,0 ≤ （left margin + right margin, ≤ 47),default 0.

    - #### setPrintRightMargin

          public void setPrintRightMargin(int margin)

      设置左边距
      Setup right margin
      Specified by:
        `setPrintRightMargin` in interface `IPrinter`
      Parameters:
        `margin` - (0 ≤ left margin ≤ 47，且 0 ≤ （左边距 + 右边距） ≤ 47), 默认值0
        margin (0 ≤ left margin ≤ 47,0 ≤ （left margin + right margin, ≤ 47),default 0.

    - #### setPrintCharacterStyle

          public void setPrintCharacterStyle(boolean italic,
                                             boolean frame,
                                             boolean bold,
                                             boolean doubleWidth,
                                             boolean doubleHigh,
                                             boolean white,
                                             boolean underline)

      设置字体样式
      set font style
      Specified by:
        `setPrintCharacterStyle` in interface `IPrinter`
      Parameters:
        `italic` - 斜体
        italic
        `frame` - 边框
        frame
        `bold` - 加粗
        bold
        `doubleWidth` - 倍宽
        doubleWidth
        `doubleHigh` - 倍高
        douleHigh
        `white` - 反白
        white
        `underline` - 下划线
        underline

    - #### setPrintSpeed

          public void setPrintSpeed(int speed)

      设置打印速度
      setup print velocity
      Specified by:
        `setPrintSpeed` in interface `IPrinter`
      Parameters:
        `speed` - 0:低速,1:中速,2:高速
        speed 0:low,1:medium,2:high
        备注：默认是1
        comment: default is 1

    - #### setPrintGrayLevel

          public void setPrintGrayLevel(int gray)

      设置打印 灰度
      setup print grey level
      Specified by:
        `setPrintGrayLevel` in interface `IPrinter`
      Parameters:
        `gray` - 1-8
        gray 1-8
        备注：默认是4
        comment: default is 4

    - #### restoreDefault

          public void restoreDefault()

      参数还原默认值
      parameter reset to default
      Specified by:
        `restoreDefault` in interface `IPrinter`

    - #### clearCache

          public void clearCache()

      立即清空打印缓存,清空打印机接收缓冲区和打印缓冲区
      Clear up printing cache, clear printer receive zone and buffer zone
      Specified by:
        `clearCache` in interface `IPrinter`

    - #### setBarcodeHeight

          public void setBarcodeHeight(int height)

      设置一维条码的高度
      Setup 1D barcode height
      Specified by:
        `setBarcodeHeight` in interface `IPrinter`
      Parameters:
        `height` - 高度(1-255),默认值:64
        height(1-255), default:64

    - #### setBarcodeWidth

          public void setBarcodeWidth(int width)

      设置一维条码的宽度
      Setup 1D barcode width
      Specified by:
        `setBarcodeWidth` in interface `IPrinter`
      Parameters:
        `width` - 宽度(1-6),默认值:2
        width(1-6), default:2

    - #### setBarcodeHRI

          public void setBarcodeHRI(int position)

      设置一维条码可读字符（HRI）打印位置
      setup 1D barcode readable character (HRI) print position
      Specified by:
        `setBarcodeHRI` in interface `IPrinter`
      Parameters:
        `position(0-3)` - 默认是0; [0:不打印, 1: 条码的上方 , 2:条码的下方, 3:条码的上方和下方]
        position(0-3) default is 0; [0:not print, 1:barcode up side 2: barcode down side, 3: barcode up and down]

    - #### isPowerOn

          public boolean isPowerOn()

      Specified by:
        `isPowerOn` in interface `IPrinter`

    - #### getVersion

          public java.lang.String getVersion()

      Specified by:
        `getVersion` in interface `IPrinter`

    - #### setPrinterType

          public void setPrinterType(int type)

      Specified by:
        `setPrinterType` in interface `IPrinter`

    - #### getPrinterType

          public int getPrinterType()

      Specified by:
        `getPrinterType` in interface `IPrinter`

    - #### setPrintCodePage

          public void setPrintCodePage(int page)

      Specified by:
        `setPrintCodePage` in interface `IPrinter`

    - #### getPrintCodePage

          public int getPrintCodePage()

      Specified by:
        `getPrintCodePage` in interface `IPrinter`

    - #### initFW

          public boolean initFW()

      Specified by:
        `initFW` in interface `IPrinter`

    - #### eraseFW

          public boolean eraseFW(long size)

      Specified by:
        `eraseFW` in interface `IPrinter`

    - #### upgradeFW

          public boolean upgradeFW(int packageCount,
                                   int index,
                                   int currSize,
                                   byte[] data)

      Specified by:
        `upgradeFW` in interface `IPrinter`

    - #### verifyFW

          public boolean verifyFW(int upgradeCRC)

      Specified by:
        `verifyFW` in interface `IPrinter`

    - #### eraseFlash

          public boolean eraseFlash()

      Specified by:
        `eraseFlash` in interface `IPrinter`

    - #### upgradeFont

          public boolean upgradeFont(int packageCount,
                                     int index,
                                     int currSize,
                                     byte[] data)

      Specified by:
        `upgradeFont` in interface `IPrinter`